<?php
/** Load ALL Configuration **/
require_once 'bcms-load.php';
/** Error Handle By errorTalk **/
errorTalk::initialize();
errorTalk::errorTalk_Open(); // run error talk object

/** Start Session **/
$session_db = new SessionDB();
session_set_save_handler(array(&$session_db,"open"),
        array(&$session_db,"close"),
        array(&$session_db,"read"),
        array(&$session_db,"write"),
        array(&$session_db,"destroy"),
        array(&$session_db,"gc"));
session_start();
/** Mode Rewrite **/
$conf['dir'] = str_replace('\\', '/', dirname(__FILE__));
$conf['path'] = "http://".$_SERVER['SERVER_NAME'].str_replace($_SERVER['DOCUMENT_ROOT'], '', $conf['dir']);
$conf['uri'] = str_replace($conf['dir'].'/', '', $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI']);
list($xuri) = explode('?', $conf['uri'], 2);
$uri = explode("/", $xuri);

$loadmodule = ($uri[0]) ? $uri[0] : 'index.php';
$inc = 'modules/'.$loadmodule;

if (is_dir($inc) || is_file($inc)) {
    if(is_dir($inc)) {
        include_once APSPATH.'/'.$inc.'/index.php';
    }else if(is_file($inc)) {
        include_once APSPATH.'/'.$inc;
    }
}
else {
    if(file_exists(TMPPATH.'\404.php'))
        include_once TMPPATH.'\404.php';
}

?>